package com.anzxy.home.service.impl;

import com.anzxy.home.entity.HomeTallyBook;
import com.anzxy.home.mapper.HomeTallyBookMapper;
import com.anzxy.home.service.IHomeTallyBookService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import java.util.Collection;
import java.util.Date;

/**
 * <p>
 * 家庭记账本 服务实现类
 * </p>
 *
 * @author ZQ
 * @since 2024-12-27
 */
@Service
public class HomeTallyBookServiceImpl extends ServiceImpl<HomeTallyBookMapper, HomeTallyBook> implements IHomeTallyBookService {
    
    @Override
    public void submit(HomeTallyBook entity) {
        final Integer id = entity.getId();
        if (id != null && this.baseMapper.exists(Wrappers.<HomeTallyBook>lambdaQuery().eq(HomeTallyBook::getId, id))) {
            entity.setUpdateTime(new Date());
            this.baseMapper.updateById(entity);
        } else {
            entity.setCreateTime(new Date());
            this.baseMapper.insert(entity);
        }
    }

    @Override
    public void delete(Collection<?> list) {
        this.removeByIds(list);
    }

    @Override
    public Page<HomeTallyBook> page(Page<HomeTallyBook> page, HomeTallyBook query) {
        LambdaQueryWrapper<HomeTallyBook> queryWrapper = Wrappers.lambdaQuery();
        return this.baseMapper.selectPage(page, queryWrapper);
    }
}
